home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / Programming Stuff / Interfaces / CIncludes / MIDI.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-11  |  11.4 KB  |  313 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        MIDI.h
  3.  
  4.      Copyright:    © 1984-1994 by Apple Computer, Inc.
  5.                  All rights reserved.
  6.  
  7.      Version:    Universal Interfaces 2.0a3  ETO #16, MPW prerelease.  Friday, November 11, 1994. 
  8.  
  9.      Bugs?:        If you find a problem with this file, send the file and version
  10.                  information (from above) and the problem description to:
  11.  
  12.                      Internet:    apple.bugs@applelink.apple.com
  13.                      AppleLink:    APPLE.BUGS
  14.  
  15. */
  16.  
  17. #ifndef __MIDI__
  18. #define __MIDI__
  19.  
  20.  
  21. #ifndef __ERRORS__
  22. #include <Errors.h>
  23. #endif
  24. /*    #include <ConditionalMacros.h>                                */
  25.  
  26. #ifndef __TYPES__
  27. #include <Types.h>
  28. #endif
  29.  
  30. #ifndef __MIXEDMODE__
  31. #include <MixedMode.h>
  32. #endif
  33.  
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37.  
  38. #if GENERATINGPOWERPC
  39. #pragma options align=mac68k
  40. #endif
  41.  
  42. #ifdef __CFM68K__
  43. #pragma lib_export on
  44. #endif
  45.  
  46.  
  47. enum {
  48.     midiToolNum                    = 4,                            /*tool number of MIDI Manager for SndDispVersion call*/
  49.     midiMaxNameLen                = 31,                            /*maximum number of characters in port and client names*/
  50. /* Time formats */
  51.     midiFormatMSec                = 0,                            /*milliseconds*/
  52.     midiFormatBeats                = 1,                            /*beats*/
  53.     midiFormat24fpsBit            = 2,                            /*24 frames/sec.*/
  54.     midiFormat25fpsBit            = 3,                            /*25 frames/sec.*/
  55.     midiFormat30fpsDBit            = 4,                            /*30 frames/sec. drop-frame*/
  56.     midiFormat30fpsBit            = 5,                            /*30 frames/sec.*/
  57.     midiFormat24fpsQF            = 6,                            /*24 frames/sec. longInt format */
  58.     midiFormat25fpsQF            = 7,                            /*25 frames/sec. longInt format */
  59.     midiFormat30fpsDQF            = 8,                            /*30 frames/sec. drop-frame longInt format */
  60.     midiFormat30fpsQF            = 9,                            /*30 frames/sec. longInt format */
  61.     midiInternalSync            = 0,                            /*internal sync*/
  62.     midiExternalSync            = 1,                            /*external sync*/
  63. /* Port types*/
  64.     midiPortTypeTime            = 0,                            /*time port*/
  65.     midiPortTypeInput            = 1,                            /*input port*/
  66.     midiPortTypeOutput            = 2,                            /*output port*/
  67.     midiPortTypeTimeInv            = 3,                            /*invisible time port*/
  68. /* OffsetTimes  */
  69.     midiGetEverything            = 0x7FFFFFFF,                    /*get all packets, regardless of time stamps*/
  70.     midiGetNothing                = 0x80000000L,                    /*get no packets, regardless of time stamps*/
  71.     midiGetCurrent                = 0x00000000                    /*get current packets only*/
  72. };
  73.  
  74. /*    MIDI data and messages are passed in MIDIPacket records (see below).
  75.     The first byte of every MIDIPacket contains a set of flags
  76.  
  77.     bits 0-1    00 = new MIDIPacket, not continued
  78.                      01 = begining of continued MIDIPacket
  79.                      10 = end of continued MIDIPacket
  80.                      11 = continuation
  81.     bits 2-3     reserved
  82.  
  83.     bits 4-6      000 = packet contains MIDI data
  84.  
  85.                   001 = packet contains MIDI Manager message
  86.  
  87.     bit 7         0 = MIDIPacket has valid stamp
  88.                   1 = stamp with current clock
  89. */
  90. enum {
  91.     midiContMask                = 0x03,
  92.     midiNoCont                    = 0x00,
  93.     midiStartCont                = 0x01,
  94.     midiMidCont                    = 0x03,
  95.     midiEndCont                    = 0x02,
  96.     midiTypeMask                = 0x70,
  97.     midiMsgType                    = 0x00,
  98.     midiMgrType                    = 0x10,
  99.     midiTimeStampMask            = 0x80,
  100.     midiTimeStampCurrent        = 0x80,
  101.     midiTimeStampValid            = 0x00,
  102. /* MIDIPacket command words (the first word in the data field for midiMgrType messages) */
  103.     midiOverflowErr                = 0x0001,
  104.     midiSCCErr                    = 0x0002,
  105.     midiPacketErr                = 0x0003,
  106. /*all command words less than this value are error indicators*/
  107.     midiMaxErr                    = 0x00FF,
  108. /* Valid results to be returned by readHooks */
  109.     midiKeepPacket                = 0,
  110.     midiMorePacket                = 1,
  111.     midiNoMorePacket            = 2,
  112. /* Driver calls */
  113.     midiOpenDriver                = 1,
  114.     midiCloseDriver                = 2
  115. };
  116.  
  117. struct MIDIPacket {
  118.     UInt8                            flags;
  119.     UInt8                            len;
  120.     long                            tStamp;
  121.     UInt8                            data[249];
  122. };
  123. typedef struct MIDIPacket MIDIPacket;
  124.  
  125. typedef MIDIPacket *MIDIPacketPtr;
  126.  
  127. typedef pascal short (*MIDIReadHookProcPtr)(MIDIPacketPtr myPacket, long myRefCon);
  128. typedef pascal void (*MIDITimeProcPtr)(long curTime, long myRefCon);
  129.  
  130. #if GENERATINGCFM
  131. typedef UniversalProcPtr MIDIReadHookUPP;
  132. typedef UniversalProcPtr MIDITimeUPP;
  133. #else
  134. typedef MIDIReadHookProcPtr MIDIReadHookUPP;
  135. typedef MIDITimeProcPtr MIDITimeUPP;
  136. #endif
  137.  
  138. struct MIDIClkInfo {
  139.     short                            syncType;                    /*synchronization external/internal*/
  140.     long                            curTime;                    /*current value of port's clock*/
  141.     short                            format;                        /*time code format*/
  142. };
  143. typedef struct MIDIClkInfo MIDIClkInfo;
  144.  
  145. struct MIDIIDRec {
  146.     OSType                            clientID;
  147.     OSType                            portID;
  148. };
  149. typedef struct MIDIIDRec MIDIIDRec;
  150.  
  151. struct MIDIPortInfo {
  152.     short                            portType;                    /*type of port*/
  153.     MIDIIDRec                        timeBase;                    /*MIDIIDRec for time base*/
  154.     short                            numConnects;                /*number of connections*/
  155.     MIDIIDRec                        cList[1];                    /*ARRAY [1..numConnects] of MIDIIDRec*/
  156. };
  157. typedef struct MIDIPortInfo MIDIPortInfo;
  158.  
  159. typedef MIDIPortInfo *MIDIPortInfoPtr, **MIDIPortInfoHdl, **MIDIPortInfoHandle;
  160.  
  161. struct MIDIPortParams {
  162.     OSType                            portID;                        /*ID of port, unique within client*/
  163.     short                            portType;                    /*Type of port - input, output, time, etc.*/
  164.     short                            timeBase;                    /*refnum of time base, 0 if none*/
  165.     long                            offsetTime;                    /*offset for current time stamps*/
  166.     MIDIReadHookUPP                    readHook;                    /*routine to call when input data is valid*/
  167.     long                            refCon;                        /*refcon for port (for client use)*/
  168.     MIDIClkInfo                        initClock;                    /*initial settings for a time base*/
  169.     Str255                            name;                        /*name of the port, This is a real live string, not a ptr.*/
  170. };
  171. typedef struct MIDIPortParams MIDIPortParams;
  172.  
  173. typedef MIDIPortParams *MIDIPortParamsPtr;
  174.  
  175. struct MIDIIDList {
  176.     short                            numIDs;
  177.     OSType                            list[1];
  178. };
  179. typedef struct MIDIIDList MIDIIDList;
  180.  
  181. typedef MIDIIDList *MIDIIDListPtr, **MIDIIDListHdl, **MIDIIDListHandle;
  182.  
  183. extern pascal NumVersion MIDIVersion(void)
  184.  FOURWORDINLINE(0x203C, 0x0000, 4, 0xA800);
  185. extern pascal OSErr MIDISignIn(OSType clientID, long refCon, Handle icon, ConstStr255Param name)
  186.  FOURWORDINLINE(0x203C, 0x0004, 4, 0xA800);
  187. extern pascal void MIDISignOut(OSType clientID)
  188.  FOURWORDINLINE(0x203C, 0x0008, 4, 0xA800);
  189. extern pascal MIDIIDListHandle MIDIGetClients(void)
  190.  FOURWORDINLINE(0x203C, 0x000C, 4, 0xA800);
  191. extern pascal void MIDIGetClientName(OSType clientID, Str255 name)
  192.  FOURWORDINLINE(0x203C, 0x0010, 4, 0xA800);
  193. extern pascal void MIDISetClientName(OSType clientID, ConstStr255Param name)
  194.  FOURWORDINLINE(0x203C, 0x0014, 4, 0xA800);
  195. extern pascal MIDIIDListHandle MIDIGetPorts(OSType clientID)
  196.  FOURWORDINLINE(0x203C, 0x0018, 4, 0xA800);
  197. extern pascal OSErr MIDIAddPort(OSType clientID, short BufSize, short *refnum, MIDIPortParamsPtr init)
  198.  FOURWORDINLINE(0x203C, 0x001C, 4, 0xA800);
  199. extern pascal MIDIPortInfoHandle MIDIGetPortInfo(OSType clientID, OSType portID)
  200.  FOURWORDINLINE(0x203C, 0x0020, 4, 0xA800);
  201. extern pascal OSErr MIDIConnectData(OSType srcClID, OSType srcPortID, OSType dstClID, OSType dstPortID)
  202.  FOURWORDINLINE(0x203C, 0x0024, 4, 0xA800);
  203. extern pascal OSErr MIDIUnConnectData(OSType srcClID, OSType srcPortID, OSType dstClID, OSType dstPortID)
  204.  FOURWORDINLINE(0x203C, 0x0028, 4, 0xA800);
  205. extern pascal OSErr MIDIConnectTime(OSType srcClID, OSType srcPortID, OSType dstClID, OSType dstPortID)
  206.  FOURWORDINLINE(0x203C, 0x002C, 4, 0xA800);
  207. extern pascal OSErr MIDIUnConnectTime(OSType srcClID, OSType srcPortID, OSType dstClID, OSType dstPortID)
  208.  FOURWORDINLINE(0x203C, 0x0030, 4, 0xA800);
  209. extern pascal void MIDIFlush(short refnum)
  210.  FOURWORDINLINE(0x203C, 0x0034, 4, 0xA800);
  211. extern pascal ProcPtr MIDIGetReadHook(short refnum)
  212.  FOURWORDINLINE(0x203C, 0x0038, 4, 0xA800);
  213. extern pascal void MIDISetReadHook(short refnum, ProcPtr hook)
  214.  FOURWORDINLINE(0x203C, 0x003C, 4, 0xA800);
  215. extern pascal void MIDIGetPortName(OSType clientID, OSType portID, Str255 name)
  216.  FOURWORDINLINE(0x203C, 0x0040, 4, 0xA800);
  217. extern pascal void MIDISetPortName(OSType clientID, OSType portID, ConstStr255Param name)
  218.  FOURWORDINLINE(0x203C, 0x0044, 4, 0xA800);
  219. extern pascal void MIDIWakeUp(short refnum, long time, long period, MIDITimeUPP timeProc)
  220.  FOURWORDINLINE(0x203C, 0x0048, 4, 0xA800);
  221. extern pascal void MIDIRemovePort(short refnum)
  222.  FOURWORDINLINE(0x203C, 0x004C, 4, 0xA800);
  223. extern pascal short MIDIGetSync(short refnum)
  224.  FOURWORDINLINE(0x203C, 0x0050, 4, 0xA800);
  225. extern pascal void MIDISetSync(short refnum, short sync)
  226.  FOURWORDINLINE(0x203C, 0x0054, 4, 0xA800);
  227. extern pascal long MIDIGetCurTime(short refnum)
  228.  FOURWORDINLINE(0x203C, 0x0058, 4, 0xA800);
  229. extern pascal void MIDISetCurTime(short refnum, long time)
  230.  FOURWORDINLINE(0x203C, 0x005C, 4, 0xA800);
  231. extern pascal void MIDIStartTime(short refnum)
  232.  FOURWORDINLINE(0x203C, 0x0060, 4, 0xA800);
  233. extern pascal void MIDIStopTime(short refnum)
  234.  FOURWORDINLINE(0x203C, 0x0064, 4, 0xA800);
  235. extern pascal void MIDIPoll(short refnum, long offsetTime)
  236.  FOURWORDINLINE(0x203C, 0x0068, 4, 0xA800);
  237. extern pascal OSErr MIDIWritePacket(short refnum, MIDIPacketPtr packet)
  238.  FOURWORDINLINE(0x203C, 0x006C, 4, 0xA800);
  239. extern pascal Boolean MIDIWorldChanged(OSType clientID)
  240.  FOURWORDINLINE(0x203C, 0x0070, 4, 0xA800);
  241. extern pascal long MIDIGetOffsetTime(short refnum)
  242.  FOURWORDINLINE(0x203C, 0x0074, 4, 0xA800);
  243. extern pascal void MIDISetOffsetTime(short refnum, long offsetTime)
  244.  FOURWORDINLINE(0x203C, 0x0078, 4, 0xA800);
  245. extern pascal long MIDIConvertTime(short srcFormat, short dstFormat, long time)
  246.  FOURWORDINLINE(0x203C, 0x007C, 4, 0xA800);
  247. extern pascal long MIDIGetRefCon(short refnum)
  248.  FOURWORDINLINE(0x203C, 0x0080, 4, 0xA800);
  249. extern pascal void MIDISetRefCon(short refnum, long refCon)
  250.  FOURWORDINLINE(0x203C, 0x0084, 4, 0xA800);
  251. extern pascal long MIDIGetClRefCon(OSType clientID)
  252.  FOURWORDINLINE(0x203C, 0x0088, 4, 0xA800);
  253. extern pascal void MIDISetClRefCon(OSType clientID, long refCon)
  254.  FOURWORDINLINE(0x203C, 0x008C, 4, 0xA800);
  255. extern pascal short MIDIGetTCFormat(short refnum)
  256.  FOURWORDINLINE(0x203C, 0x0090, 4, 0xA800);
  257. extern pascal void MIDISetTCFormat(short refnum, short format)
  258.  FOURWORDINLINE(0x203C, 0x0094, 4, 0xA800);
  259. extern pascal void MIDISetRunRate(short refnum, short rate, long time)
  260.  FOURWORDINLINE(0x203C, 0x0098, 4, 0xA800);
  261. extern pascal Handle MIDIGetClientIcon(OSType clientID)
  262.  FOURWORDINLINE(0x203C, 0x009C, 4, 0xA800);
  263. extern pascal long SndDispVersion(short toolnum)
  264.  FOURWORDINLINE(0x203C, 0x0000, 0x0000, 0xA800);
  265. enum {
  266.     uppMIDIReadHookProcInfo = kPascalStackBased
  267.          | RESULT_SIZE(SIZE_CODE(sizeof(short)))
  268.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(MIDIPacketPtr)))
  269.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long))),
  270.     uppMIDITimeProcInfo = kPascalStackBased
  271.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))
  272.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long)))
  273. };
  274.  
  275. #if GENERATINGCFM
  276. #define NewMIDIReadHookProc(userRoutine)        \
  277.         (MIDIReadHookUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppMIDIReadHookProcInfo, GetCurrentArchitecture())
  278. #define NewMIDITimeProc(userRoutine)        \
  279.         (MIDITimeUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppMIDITimeProcInfo, GetCurrentArchitecture())
  280. #else
  281. #define NewMIDIReadHookProc(userRoutine)        \
  282.         ((MIDIReadHookUPP) (userRoutine))
  283. #define NewMIDITimeProc(userRoutine)        \
  284.         ((MIDITimeUPP) (userRoutine))
  285. #endif
  286.  
  287. #if GENERATINGCFM
  288. #define CallMIDIReadHookProc(userRoutine, myPacket, myRefCon)        \
  289.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppMIDIReadHookProcInfo, (myPacket), (myRefCon))
  290. #define CallMIDITimeProc(userRoutine, curTime, myRefCon)        \
  291.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppMIDITimeProcInfo, (curTime), (myRefCon))
  292. #else
  293. #define CallMIDIReadHookProc(userRoutine, myPacket, myRefCon)        \
  294.         (*(userRoutine))((myPacket), (myRefCon))
  295. #define CallMIDITimeProc(userRoutine, curTime, myRefCon)        \
  296.         (*(userRoutine))((curTime), (myRefCon))
  297. #endif
  298.  
  299.  
  300. #ifdef __CFM68K__
  301. #pragma lib_export off
  302. #endif
  303.  
  304. #if GENERATINGPOWERPC
  305. #pragma options align=reset
  306. #endif
  307.  
  308. #ifdef __cplusplus
  309. }
  310. #endif
  311.  
  312. #endif /* __MIDI__ */
  313.